<template>
  <div class="profile-page">
    <div class="profile-header">
      <img src="https://images.unsplash.com/photo-1438761681033-6461ffad8d80?ixlib=rb-1.2.1&auto=format&fit=crop&w=200&q=80" alt="avatar" class="avatar">
      <h3 class="username">如花</h3>
      <p class="user-bio">热爱生活，分享美好</p>
    </div>

    <div class="profile-actions">
      <button class="btn btn-primary" @click="modifyPwd">
        <svg viewBox="0 0 24 24" width="18" height="18" class="btn-icon">
          <path fill="currentColor" d="M12,15A2,2 0 0,1 14,17A2,2 0 0,1 12,19A2,2 0 0,1 10,17A2,2 0 0,1 12,15M12,10A2,2 0 0,1 14,12A2,2 0 0,1 12,14A2,2 0 0,1 10,12A2,2 0 0,1 12,10M12,5A2,2 0 0,1 14,7A2,2 0 0,1 12,9A2,2 0 0,1 10,7A2,2 0 0,1 12,5M17,2H7A2,2 0 0,0 5,4V20A2,2 0 0,0 7,22H17A2,2 0 0,0 19,20V4A2,2 0 0,0 17,2M17,20H7V4H17V20Z" />
        </svg>
        修改密码
      </button>
      <button class="btn btn-logout" @click="logout">
        <svg viewBox="0 0 24 24" width="18" height="18" class="btn-icon">
          <path fill="currentColor" d="M16,17V14H9V10H16V7L21,12L16,17M14,2A2,2 0 0,1 16,4V6H14V4H5V20H14V18H16V20A2,2 0 0,1 14,22H5A2,2 0 0,1 3,20V4A2,2 0 0,1 5,2H14Z" />
        </svg>
        退出登录
      </button>
    </div>

    <!-- 修改密码模态框 -->
    <div class="modal" v-if="showPwdModal">
      <div class="modal-content">
        <h3>修改密码</h3>
        <div class="form-group">
          <label>原密码</label>
          <input type="password" v-model="password" placeholder="请输入原密码">
        </div>
        <div class="form-group">
          <label>新密码</label>
          <input type="password" v-model="newPassword" placeholder="请输入新密码">
        </div>
        <div class="modal-actions">
          <button class="btn btn-cancel" @click="showPwdModal = false">取消</button>
          <button class="btn btn-confirm" @click="handlePwdSubmit">确认</button>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import { useRouter } from 'vue-router'

const router = useRouter()
const password = ref('')
const newPassword = ref('')
const showPwdModal = ref(false)

const logout = () => {
  // 清除本地存储中的登录状态
  localStorage.removeItem('token')
  // 跳转到登录页，假设登录页路由为 '/login'
  router.push('/login')
}

const modifyPwd = () => {
  showPwdModal.value = true
}

const handlePwdSubmit = () => {
  // 这里简单模拟修改密码请求，实际需替换为真实接口
  console.log('原密码:', password.value, '新密码:', newPassword.value)
  alert('密码修改成功，请重新登录')
  logout()
}
</script>

<style scoped>
.profile-page {
  max-width: 600px; /* 增大卡片宽度 */
  margin: 40px auto; /* 增加外边距 */
  padding: 40px 30px; /* 增加内边距 */
  background-color: #fff;
  border-radius: 20px; /* 增大圆角 */
  box-shadow: 0 6px 30px rgba(0, 0, 0, 0.1); /* 增强阴影 */
}

.profile-header {
  text-align: center;
  margin-bottom: 40px; /* 增加间距 */
}

.avatar {
  width: 140px; /* 增大头像尺寸 */
  height: 140px;
  border-radius: 50%;
  object-fit: cover;
  border: 5px solid #f8f9fa; /* 加粗边框 */
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.12); /* 增强阴影 */
  margin-bottom: 20px;
}

.username {
  margin: 0 0 10px 0;
  font-size: 28px; /* 增大字体 */
  color: #333;
  font-weight: 600;
}

.user-bio {
  margin: 0;
  color: #666;
  font-size: 16px; /* 增大字体 */
}

.profile-actions {
  display: flex;
  justify-content: center;
  gap: 20px; /* 增加按钮间距 */
  margin-top: 40px;
}

.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px 24px; /* 增大按钮尺寸 */
  border-radius: 12px; /* 增大圆角 */
  font-size: 16px; /* 增大字体 */
  font-weight: 500;
  cursor: pointer;
  transition: all 0.3s ease;
  border: none;
}

.btn-icon {
  margin-right: 10px;
  width: 20px; /* 增大图标 */
  height: 20px;
}

.btn-primary {
  background-color: #4361ee;
  color: white;
}

.btn-primary:hover {
  background-color: #3a56d4;
  transform: translateY(-2px);
}

.btn-logout {
  background-color: #f8f9fa;
  color: #666;
  border: 1px solid #eee;
}

.btn-logout:hover {
  background-color: #f1f3f5;
  transform: translateY(-2px);
}

/* 模态框样式 */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal-content {
  background-color: white;
  padding: 30px;
  border-radius: 16px;
  width: 90%;
  max-width: 450px; /* 增大模态框 */
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
}

.modal h3 {
  margin-top: 0;
  margin-bottom: 25px;
  text-align: center;
  color: #333;
  font-size: 22px; /* 增大标题 */
}

.form-group {
  margin-bottom: 25px;
}

.form-group label {
  display: block;
  margin-bottom: 10px;
  font-size: 16px; /* 增大标签 */
  color: #555;
}

.form-group input {
  width: 100%;
  padding: 12px 15px; /* 增大输入框 */
  border: 1px solid #ddd;
  border-radius: 10px;
  font-size: 16px;
  transition: border 0.3s;
}

.form-group input:focus {
  border-color: #4361ee;
  outline: none;
}

.modal-actions {
  display: flex;
  justify-content: center;
  gap: 20px;
  margin-top: 25px;
}

.btn-cancel {
  background-color: #f8f9fa;
  color: #666;
}

.btn-confirm {
  background-color: #4361ee;
  color: white;
}

.btn-cancel:hover, .btn-confirm:hover {
  transform: translateY(-2px);
}
</style>
